// Convoy Weapon Dropoff
// convoyUnload.sqf

if (!(isserver)) exitWith {};
_crate			= konvoybox;
_art				= _this select 1;
_respawn			= _this select 2;
_copcrate			= _this select 3;
_rezeitcrate		= 1;
crateweaponarray		= [];
cratemagarray		= [];


if (not(_crate == dummyobj)) then 
{
	format ["
	ClearMagazineCargo %1;
	ClearWeaponCargo %1;
	", konvoybox] call Isse_Pub_execPstr;
};


if ((_art == 1) or (_art == 2) or (_art == 3) or (_art == 4) or (_art == 5)) then 
{
	switch (_art) do 
	{

		case 1: 
		{
			crateweaponarray	= [ ];
			cratemagarray		= [ ["M136", 10], ["STINGER", 10], ["PG7V", 10], ["PG7VR", 5], ["STRELA", 25], ["ACE_40mm_FlareGreen_M203", 8], ["ACE_40mm_FlareWhite_M203", 8], ["ACE_40mm_FlareRed_M203", 8], ["ACE_40mm_FlareYellow_M203", 8], ["ACE_40mm_HEDP_M203", 8], ["ACE_40mm_FlareWhite_GP25", 8],  ["ACE_40mm_FlareGreen_GP25", 8], ["ACE_40mm_FlareRed_GP25", 8], ["ACE_40mm_FlareYellow_GP25", 8], ["ACE_40mm_HEDP_GP25", 8] ];
		};

		case 2: 
		{
			crateweaponarray	= [ ];
			cratemagarray		= [ ["ACE_30Rnd_9x19_B_MP5", 64], ["ACE_30Rnd_9x19_SD_MP5", 32], ["ACE_30Rnd_545x39_B_AK", 32], ["ACE_30Rnd_545x39_SD_AK", 32], ["ACE_10Rnd_762x54_SB_SVD", 32], ["ACE_100Rnd_762x54_B_PK", 32], ["ACE_30Rnd_556x45_B_G36", 128], ["ACE_30Rnd_556x45_B_Stanag", 32], ["ACE_30Rnd_556x45_SD_Stanag", 32], ["ACE_200Rnd_556x45_B_M249", 32], ["ACE_100Rnd_762x51_B_M240", 32], ["ACE_5Rnd_762x51_SB", 32], ["ACE_10Rnd_127x99_SB_Barrett", 12], ["ACE_5Rnd_127x108_SB_KSVK", 12] ];
		};
		
		case 3: 
		{
			crateweaponarray	= [ ];
			cratemagarray		= [ ["ACE_HandGrenadeRGO", 32], ["ACE_HandGrenadeTimed", 32], ["ACE_SmokeGrenade_Red", 16], ["ACE_SmokeGrenade_Green", 16], ["ACE_SmokeGrenade_White", 16], ["ACE_PipeBomb", 8], ["ACE_Mine", 8] ];
		};
		
		case 4: 
		{
			crateweaponarray	= [ ["NVGoggles", 16], ["Binocular", 16] ];
			cratemagarray		= [ ];
		};
		
		case 5: {
			crateweaponarray	= [ ];
			cratemagarray		= [ ["ACE_30Rnd_9x19_SD_MP5", 32], ["ACE_30Rnd_9x19_B_MP5", 32], ["8Rnd_9x18_Makarov", 64], ["8Rnd_9x18_MakarovSD", 64], ["15Rnd_9x19_M9", 64], ["15Rnd_9x19_M9SD", 64] ];
		};
	};
	
	while {true} do 
	{
		sleep _rezeitcrate;
		ClearMagazineCargo _crate;
		ClearWeaponCargo   _crate;
		_crate SETDAMAGE 0;
		{_crate addWeaponCargo   [(_x select 0), (_x select 1)];}forEach crateweaponarray;
		{_crate addMagazineCargo [(_x select 0), (_x select 1)];}forEach cratemagarray;
		if (_respawn == 0) exitWith {};
		if (_copcrate != 1) then {_rezeitcrate = 300;};
		waituntil {(konvoytruck distance copbase1 <= 250) or (_copcrate != 1)};
	};
};


// For Terrorbase Convoy drop-off
if (_art == 6) then 
{
	
	_randomizer = ceil random 3;
	if (interndebug) then {_randomizer = ceil random 1;};
	switch (_randomizer) do 
	{
		case 1: 
		{
			// Terrorist gets Police Pistols
			crateweaponarray	= [ ["RH_mk22", 5],["RH_usp", 2],["RH_uspm", 3],["ACE_M9", 10], ["arpg_Glock21", 5], ["RH_mk2", 10], ["RH_ppk", 5] ];
			cratemagarray		= [ ["15Rnd_9x19_usp", 25], ["8Rnd_9x19_Mk", 25], ["12Rnd_45cal_usp", 20], ["10Rnd_22LR_mk2", 20], ["arpg_13Rnd_45acp_G21", 30], ["ACE_15Rnd_9x19_B_M9", 50], ["7Rnd_32cal_ppk", 25] ];
		};

		case 2: 
		{
			// Terrorist gets some CRO Guns
			crateweaponarray	= [ ["RH_m93r", 8], ["ACE_Glock18", 5], ["RH_muzi", 5], ["ACE_MP5A5", 5], ["ACE_MP5A4", 5], ["ACE_UMP45", 3], ["ACE_M1014", 2], ["ACE_M1014_Eotech", 2], ["arpg_bushmasterM4Iron", 2], ["arpg_ColtAr15", 1]];
			cratemagarray		= [ ["20Rnd_9x19_M93", 55], ["ACE_33Rnd_9x19_G18", 40], ["arpg_10Rnd_556x45", 30], ["32Rnd_9x19_Muzi", 40], ["ACE_30Rnd_9x19_B_MP5", 50], ["ACE_25Rnd_1143x23_B_UMP45", 30], ["ACE_8Rnd_12Ga_Buck00", 20], ["ACE_8Rnd_12Ga_Slug", 20], ["8Rnd_127x51_Shell_TR", 20], ["8Rnd_127x51_tazerxrep", 10] ];
		};
		
		case 3: 
		{
			// Terrorist gets Swat-Guns 1
			crateweaponarray	= [ ["ACE_M1014_Eotech", 2], ["ACE_SPAS12", 2], ["arpg_beowulf50", 1], ["ACE_M4A1", 3], ["ACE_M4A1AimPointSD", 1], ["ACE_M16A4GLAimPoint", 1], ["ACE_M4A1GL", 2], ["ACE_UMP45_SD", 3], ["ACE_MP5SD", 2], ["ACE_G36C_CompEo", 2], ["ACE_G36C", 2], ["ACE_G36K", 3] ];
			cratemagarray		= [ ["ACE_30Rnd_9x19_SD_MP5", 50], ["ACE_30Rnd_9x19_B_MP5", 20], ["ACE_25Rnd_1143x23_B_UMP45", 30], ["ACE_8Rnd_12Ga_Buck00", 20], ["ACE_8Rnd_12Ga_Slug", 20], ["ACE_9Rnd_12Ga_Buck00", 20], ["ACE_9Rnd_12Ga_Slug", 20], ["8Rnd_127x51_Shell_TR", 20], ["8Rnd_127x51_tazerxrep", 10], ["8Rnd_127x51_ball_TR", 10], ["ACE_30Rnd_556x45_B_Stanag", 50], ["ACE_30Rnd_556x45_BT_Stanag", 50], ["ACE_30Rnd_556x45_B_G36", 40], ["ACE_30Rnd_556x45_BT_G36", 40], ["ACE_100Rnd_556x45_B_G36", 5], ["ACE_100Rnd_556x45_BT_G36", 7] ];
		};
		
		case 4: 
		{
			// Terrorist gets Swat-Guns 2
			crateweaponarray	= [ ["NVGoggles", 16], ["Binocular", 16] ];
			cratemagarray		= [ ];
		};
		
		case 5: {
			// Terrorist gets Mixture
			crateweaponarray	= [ ["ACE_M9", 8], ["ACE_MP5A4", 5] ];
			cratemagarray		= [ ["ACE_30Rnd_9x19_SD_MP5", 32], ["ACE_30Rnd_9x19_B_MP5", 32], ["15Rnd_9x19_M9", 64], ["15Rnd_9x19_M9SD", 64] ];
		};
	
	};
	publicVariable "crateweaponarray";
	publicVariable "cratemagarray";
	konvoybox setdamage 0;
	sleep 3;
	format ["
	ClearMagazineCargo %1;
	ClearWeaponCargo %1;
	{%1 addWeaponCargo   [(_x select 0), (_x select 1)];} forEach crateweaponarray;
	{%1 addMagazineCargo [(_x select 0), (_x select 1)];} forEach cratemagarray;
	", konvoybox] call Isse_Pub_execPstr;
};
